export default [
  /* 登录 */
  {
    url: "/mock/api/login",
    method: "post",
    response: ({ body }) => {
      const users = [
        {
          username: "admin",
          password: "123456",
          token: "admin-token",
          role: "admin",
          post: "技术开发",
          realName: "万里",
          avatar: "https://avatars.githubusercontent.com/u/1234567?v=4",
        },
        {
          username: "user",
          password: "123456",
          token: "user-token",
          role: "user",
          avatar: "https://avatars.githubusercontent.com/u/7654321?v=4",
        },
      ];

      const user = users.find(
        (user) =>
          user.username === body.username && user.password === body.password
      );

      if (!user) {
        return {
          code: 401,
          message: "用户名或密码错误",
          data: null,
        };
      }

      return {
        code: 200,
        message: "登录成功",
        data: {
          token: user.token,
          userInfo: {
            post: user.post,
            realName: user.realName,
            avatar: user.avatar,
          },
        },
      };
    },
  },
  /* 菜单 */
  {
    url: "/mock/api/user/menus",
    method: "post",
    response: ({ headers }) => {
      // 获取请求头中的token
      const token = headers?.authorization || "";
      const actualToken = token.startsWith("Bearer ")
        ? token.replace("Bearer ", "")
        : "";

      if (actualToken !== "admin-token") {
        return {
          code: 401,
          message: "登录已过期，请重新登录",
          data: null,
        };
      }

      const menus = [
        {
          path: "/system",
          menuName: "System",
          menuId: "1",
          component: null,
          redirect: "/system/user/list",
          meta: {
            title: "系统管理",
            icon: "eos-icons:system-ok-outlined",
          },
          children: [
            {
              path: "/system/user",
              menuName: "UserList",
              menuId: "1-1-1",
              component: "System/User/index",
              meta: {
                title: "用户列表",
                icon: "mdi:account-group",
              },
            },
            {
              path: "/system/role",
              menuName: "UserRole",
              menuId: "1-1-2",
              component: "System/Role/index",
              meta: {
                title: "角色管理",
                icon: "mdi:shield-account",
              },
            },
          ],
        },
        {
          path: "/dashboard",
          menuName: "Dashboard",
          menuId: "2",
          component: "Dashboard/index",
          meta: {
            title: "仪表盘",
            icon: "mdi:view-dashboard",
          },
        },
        {
          path: "/ocr",
          menuName: "OCR",
          menuId: "3",
          component: null,
          redirect: "/ocr/face-recognition",
          meta: {
            title: "OCR识别",
            icon: "mdi:text-recognition",
          },
          children: [
            {
              path: "/ocr/face-recognition",
              menuName: "FaceRecognition",
              menuId: "3-1",
              component: "OCR/FaceRecognition/index",
              meta: {
                title: "人脸识别",
                icon: "mdi:face-recognition",
              },
            },
          ],
        },
      ];

      return {
        code: 200,
        message: "请求成功",
        data: menus,
      };
    },
  },
];
